//通配符上界和下界
/**
 * 通配符上界：不能放只能取
 * 不能放：
 * 可以取：取的元素发生向上转型
 */

/**
 * 通配符的下界:可以放本身和子类，不能放父类，不能取数据
 *
 */
class Food{

}
class Fruit extends Food{

}
class Apple extends Fruit{

}
class Banana extends Fruit{

}
class Plate<T>{
    private T plate;
    public Plate(){

    }

    public Plate(T plate) {
        this.plate = plate;
    }

    public T getPlate() {
        return plate;
    }

    public void setPlate(T plate) {
        this.plate = plate;
    }
}
public class Test {
    //下界是Fruit->Fruit 或 Fruit的父类
    public static void func(Plate<? super Fruit> tmp){
        tmp.setPlate(new Fruit());
        tmp.setPlate(new Apple());
    }
    public static void main(String[] args) {
        Plate<Fruit> plate = new Plate<>();
        func(plate);
        Plate<Food> plate1 = new Plate<>();
        func(plate1);
    }
    //不能太通配了，是有边界的，必须是Fruit或Fruit的子类
    public static void fun(Plate<? extends Fruit> temp){
        Fruit fruit = temp.getPlate();
        System.out.println(fruit);
    }
    public static void main1(String[] args) {
        Plate<Apple> plate = new Plate<>(new Apple());
        fun(plate);
        Plate<Banana> plate1 = new Plate<>(new Banana());
        fun(plate1);

    }
}
